programming4us
           
 
 
Windows

Windows Azure : Programming Access Control Service (part 4)

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/4/2010 11:44:53 AM

Listing 4 shows the code for the TokenValidator constructor.

Example 4. TokenValidator Constructor
public TokenValidator(string acsHostName, string trustedSolution,
string trustedAudienceValue, byte[] trustedSigningKey)
{
this.acsHostName = acsHostName;
this.trustedSigningKey = trustedSigningKey;

this.trustedTokenIssuer = new Uri(string.Format(
CultureInfo.InvariantCulture,
"https://{0}.{1}/WRAPv0.8",
trustedSolution,
acsHostName));

this.trustedAudienceValue = new Uri(trustedAudienceValue);
}

In Listing 4, trustedSolution represents your ACS service namespace, trustedAudienceValue represents the destination URL where the ACS token will be sent, and trustedSigningKey represents the token policy key associated with the token issuer your trust. In this case, the authority is ACS. Listing 5 shows the code for the Validate() method used to validate the token issued by ACS.

Example 5. TokenValidator Validate Method
public bool Validate(string token)
{
if (!this.IsHMACValid(token, this.trustedSigningKey))
{
return false;
}

if (this.IsExpired(token))
{
return false;
}

if (!this.IsIssuerTrusted(token))
{
return false;
}

if (!this.IsAudienceTrusted(token))
{
return false;
}

return true;
}

The Validate() method checks the token validity, token expiration, issuer validity, and intended audience for the token. If all the checks pass, the method returns true. The utility functions IsHMACValid(), IsExpired(), IsIssuerTrusted(), and IsAudienceTrusted() drill down into the SWT token format to examine the respective validity of the token.

The Program.cs file in the Service project includes the startup logic for the web service. Listing 6 shows the web service startup code.

Example 6. Web Service Startup Code
class Program
{
const string serviceNamespace = "proazure-1";
const string trustedTokenPolicyKey = "peCRAARL9t/oji4/CWvVKLNcS2KOMiRnHscdcw5HDJQ=";

const string acsHostName = "accesscontrol.windows.net";
const string trustedAudience = "http://localhost/acsexample";
const string requiredClaimType = "action";

static void Main()
{
WebHttpBinding binding =
new WebHttpBinding(WebHttpSecurityMode.None);

Uri address = new Uri(trustedAudience);

WebServiceHost host = new WebServiceHost(typeof(ACSExample));
host.AddServiceEndpoint(typeof(IACSExample), binding, address);

host.Authorization.ServiceAuthorizationManager =
new ACSAuthorizationManager(
acsHostName,
serviceNamespace,
trustedAudience,
Convert.FromBase64String(trustedTokenPolicyKey),
requiredClaimType);

host.Open();

Console.WriteLine("The ACSExample Service is listening");
Console.WriteLine("Press <ENTER> to exit");
Console.ReadLine();

host.Close();
}
}


In Listing 6, trustedTokenPolicyKey is the token policy key created when you create the token policy. requiredClaimType is the claim type that the web service expects from the SWT issued by ACS. Note that the ServiceAuthorizationManager property of the host.Authorization object is set to the custom class ACSAuthorizationManager. When you set this property, the method call to the web service is automatically intercepted for validation purposes. The web service is now ready to accept and process SWT tokens from ACS. Listing 7 shows the interface of the web service.

Example 7. ACSMachineInfo Interface
[ServiceContract]
public interface IACSExample
{
[OperationContract]
[WebGet(UriTemplate = "getmachinename")]
string GetMachineName();

[OperationContract]
[WebGet(UriTemplate = "getuserdomainname")]
string GetUserDomainName();

[OperationContract]
[WebGet(UriTemplate = "getosversion")]
string GetOSVersion();


[OperationContract]
[WebGet(UriTemplate = "encodestring?data={data}")]
byte[] EncodeString(string data);

}

The UriTemplate property represents the value that is returned when you call the WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RelativePathSegments.First() method in the TokenValidator.CheckAccessCore() method.
Other -----------------
- Windows 7 : Working with Registry Entries (part 3)
- Windows 7 : Working with Registry Entries (part 2)
- Windows 7 : Working with Registry Entries (part 1) - Changing the Value of a Registry Entry
- Windows 7 : Keeping the Registry Safe
- Windows 7 : Getting to Know the Registry (part 2)
- Windows 7 : Getting to Know the Registry (part 1) - Understanding Registry Settings
- Windows 7 : Firing Up the Registry Editor
- Windows Azure : Managing Access Control Service Resources (part 2)
- Windows Azure : Managing Access Control Service Resources (part 1)
- Windows Azure : Access Control Service Management Portal
- Windows 7 : Reset a Broken Service
- Windows 7 : Make Windows Shut Down Services Faster
- Windows 7 : Disable Services for Faster Performance
- Windows 7 : Controlling Services with a Script
- Windows 7 : Controlling Services at the Command Prompt
- Windows 7 : Controlling Services with the Services Snap-In
- Windows Azure : Access Control Service Usage Scenarios (part 3)
- Windows Azure : Access Control Service Usage Scenarios (part 2)
- Windows Azure : Access Control Service Usage Scenarios (part 1)
- Windows Azure : Access Control Service - Claims-Based Identity Model
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us